if not NDB then
	NDB = NULL
end

include("sh_obj_player_extend.lua")
include("sh_animations.lua")
include("sh_micro.lua")
include("sh_options.lua")

include("obj_entity_extend.lua")

GM.Name = "Hover Gear Legacy"
GM.Author = "William \"JetBoom\" Moodhe"
GM.Email = "jetboom@noxiousnet.com"
GM.Website = "www.noxiousnet.com"
GM.Version = "1.01"

GM.Credits = {
	{"William \"JetBoom\" Moodhe", "http://www.noxiousnet.com (jetboom@noxiousnet.com)", "Original Project Lead / Programmer"},
	{"ptown2", "xptown2x@gmail.com", "GMOD13 Conversioner / Programmer"},
	{"Rover", "-", "Project Revival Sub-Lead"}
}

GM.Winner = GM.Winner or NULL
GM.Winstreaks = GM.Winstreaks or 0
GM.MaxCheckpoint = GM.MaxCheckpoint or 0
GM.VehicleClass = "vehicle__base_hover"
GM.Checkpoints = GM.Checkpoints or {}

if NDB.MemberNames then
	GM.HatsDisabled = true
	GM.BloodDyesDisabled = true
	GM.BodysDisabled = true
	GM.AccsDisabled = true
end

TEAM_NOTRACING = 1
TEAM_CROWD = TEAM_NOTRACING
TEAM_RED = TEAM_NOTRACING
TEAM_RACING = 2
TEAM_BLUE = TEAM_RACING
TEAM_RACERS = TEAM_RACING

team.SetUp(TEAM_CROWD, "The Crowd", Color(255, 50, 50, 255), true)
team.SetSpawnPoint(TEAM_CROWD, "info_player_crowd")

team.SetUp(TEAM_RACING, "Racers", Color(30, 255, 30, 255))
team.SetSpawnPoint(TEAM_RACING, "info_player_racer", true)

SOUNDBARRIER = 13500 * SCALE

PickupTranslates = {
	["default"] = ". . .",
	["weapon_tier1"] = "Random Weapon Tier 1",
	["weapon_tier2"] = "Random Weapon Tier 2",
	["weapon_tier3"] = "Random Weapon Tier 3",
	["weapon_tier4"] = "Random Weapon Tier 4",
	["weapon_tier5"] = "Random Weapon Tier 5",
	["weapon_def_tier1"] = "Random Defense Tier 1",
	["weapon_def_tier2"] = "Random Defense Tier 2",
	["weapon_def_tier3"] = "Random Defense Tier 3",
	["powerup_tier1"] = "Random Powerup Tier 1",
	["powerup_tier2"] = "Random Powerup Tier 2",
	["powerup_tier3"] = "Random Powerup Tier 3",
	["powerup_tier4"] = "Random Powerup Tier 4",
	["powerup_tier5"] = "Random Powerup Tier 5"
}

PICKUP_GROUPS = {
	["weapon_tier1"] = {},
	["weapon_tier2"] = {},
	["weapon_tier3"] = {},
	["weapon_tier4"] = {},
	["weapon_tier5"] = {},
	["weapon_tier6"] = {},
	["weapon_def_tier1"] = {},
	["weapon_def_tier2"] = {},
	["weapon_def_tier3"] = {},
	["weapon_def_tier4"] = {},
	["weapon_def_tier5"] = {},
	["weapon_def_tier6"] = {},
	["powerup_tier1"] = {},
	["powerup_tier2"] = {},
	["powerup_tier3"] = {},
	["powerup_tier4"] = {},
	["powerup_tier5"] = {},
	["powerup_tier6"] = {}
}

GM.Queue = GM.Queue or {}

function gmod.BroadcastLua(lua)
	for _, pl in pairs(player.GetAll()) do
		pl:SendLua(lua)
	end
end

function LogAction(str)
	for _, v in pairs(player.GetAll()) do
		v:ChatPrint(str)
	end
end

function SortPlayers(a, b)
	if IsValid(a) and IsValid(b) then
		local alap, blap = a:GetLap(), b:GetLap()
		if alap == blap then 
			local acheck, bcheck = a:GetCheckpoint(), b:GetCheckpoint()
			if acheck == bcheck then
				local adist, bdist = a:GetDistance(), b:GetDistance()
				if adist ==  bdist then
					return a:UserID() > b:UserID()
				end
				return adist < bdist
			end
			return acheck > bcheck
		end
		return alap > blap
	else
		return a
	end
end

function GM:GravGunPickupAllowed(pl, ent)
	return false
end

function GM:AddPickup(class, name, model, scale, customdraw)
	if class then
		PickupTranslates[class] = name
		if CLIENT then
			PowerupDrawScales[class] = scale
			PowerupDrawModels[class] = model
			CustomDrawFunctions[class] = customdraw
		end
	else
		ErrorNoHalt("Attempt to add a nil pickup class!")
	end
end

function GM:AddPickupToTier(class, tiername)
	if class then
		if not PICKUP_GROUPS[tiername] then
			PICKUP_GROUPS[tiername] = {}
		end
		table.insert(PICKUP_GROUPS[tiername], class)
	else
		ErrorNoHalt("Attempt to add a nil pickup to a tier!")
	end
end

function GM:KeyPress(pl, key)
	local vehicle = pl:GetHoverGear()
	if vehicle:IsValid() then
		vehicle:KeyPress(pl, key)
	end
end

function GM:KeyRelease(pl, key)
	local vehicle = pl:GetHoverGear()
	if vehicle:IsValid() then
		vehicle:KeyRelease(pl, key)
	end
end

function GM:PhysgunPickup(pl, ent)
	return true
end

function GM:GetGameDescription()
	return self.Name
end

function GM:PlayerStepSoundTime(pl, iType, bWalking)
	return self.BaseClass.PlayerStepSoundTime(self, pl, iType, bWalking) --* SCALE
end

function TrueVisible(posa, posb)
	local filt = ents.FindByClass("projectile_*")
	filt = table.Add(filt, ents.FindByClass("npc_*"))
	filt = table.Add(filt, ents.FindByClass("prop_physics*"))
	filt = table.Add(filt, ents.FindByClass("prop_vehicle*"))
	filt = table.Add(filt, ents.FindByClass("vehicle*"))
	if GAMEMODE.FlagEntity then
		filt = table.Add(filt, ents.FindByClass(GAMEMODE.FlagEntity))
	end
	filt = table.Add(filt, player.GetAll())

	return not util.TraceLine({start = posa, endpos = posb, filter = filt, mask = MASK_SHOT}).Hit
end

if CLIENT then
	surface.CreateFont("DefaultBold", {
		font 	= "Tahoma",
		size 	= 48,
		weight	= 1000
	})
	surface.CreateFont("NoticeBig", {
		font 	= "coolvetica",
		size 	= 36,
		weight	= 500
	})
	surface.CreateFont("NoticeMedium", {
		font 	= "coolvetica",
		size 	= 28,
		weight	= 500
	})
	surface.CreateFont("NoticeSmall", {
		font 	= "coolvetica",
		size 	= 20,
		weight	= 500
	})
	surface.CreateFont("ScoreboardHead", {
		font 	= "coolvetica",
		size 	= 48,
		weight	= 500
	})
	surface.CreateFont("ScoreboardSub", {
		font 	= "coolvetica",
		size 	= 24,
		weight	= 500
	})
	surface.CreateFont("ScoreboardText", {
		font 	= "coolvetica",
		size 	= 18,
		weight	= 250
	})
end